package base.exa18;

import java.util.Scanner;

public class ScannerDemo {
    public static void main(String[] args) {
        ScannerSysIn();
    }

    /**
     * Scanner作为数据扫描器，
     * 它可以让控制台输入的字符放到程序中来，
     * 这是的最简单用法
     */
    public static void ScannerSysIn(){
        System.out.println("你好，欢迎来到问答游戏");
        System.out.println("你准备好啦吗？ 准备好啦请按Y");
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        if(str.equals("Y")||str.equals("y")){
            System.out.println("1+1=？");
            while (true){
                try {
                    Scanner scanner = new Scanner(System.in);
                    int num = scanner.nextInt();
                    if(num==2){
                        System.out.println("恭喜你，回答正确！得分");
                    }else{
                        System.out.println("很遗憾，回答错误....");
                    }
                    break;
                }catch (Exception e){
                    System.out.println("请输入正确的字符哦！");
                }
            }
            System.out.println("1+2=?");
            while (true){
                try {
                    Scanner scanner = new Scanner(System.in);
                    int num = scanner.nextInt();
                    if(num==3){
                        System.out.println("恭喜你，回答正确！得分");
                    }else{
                        System.out.println("很遗憾，回答错误....");
                    }
                    break;
                }catch (Exception e){
                    System.out.println("请输入正确的字符哦！");
                }
            }
        }
        System.out.println("游戏结束！！");
    }
}
